//
//  SelectPayMethodsView.m
//  ForestPack
//
//  Created by 骆锴 on 2018/8/10.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SelectPayMethodsView.h"

@interface SelectPayMethodsView ()

@property (nonatomic, strong) UIButton *balancePay;
@property (nonatomic, strong) UIButton *weiXinPay;
@property (nonatomic, strong) UIButton *aLiPay;
@property (nonatomic, strong) UIButton *bankCardPay;

@end

@implementation SelectPayMethodsView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        _is_weiXin = YES;
        _is_aLiPay = NO;
        _is_bankCard = NO;
        _is_wallet = NO;
        
        self.shadowBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.shadowBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        self.shadowBtn.alpha = 0;
        [self.shadowBtn addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.shadowBtn];
        
        UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - ScreenX375(332), SCREEN_WIDTH, ScreenX375(332))];
        baseView.backgroundColor = [UIColor whiteColor];
        [self addSubview:baseView];
        
        UIButton *back = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(17), ScreenX375(7), ScreenX375(12))];
        [back setImage:[UIImage imageNamed:@"返回灰色"] forState:UIControlStateNormal];
        [back addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:back];
        
        UILabel *willpay =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(127), ScreenX375(15), ScreenX375(80), ScreenX375(18))];
        willpay.text = @"需支付";
        willpay.font = Kfont(18);
        willpay.textColor = REXADECIMALCOLOR(@"#333333");
        willpay.textAlignment = NSTextAlignmentLeft;
        [baseView addSubview:willpay];

        _price =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(196), ScreenX375(15), ScreenX375(80), ScreenX375(18))];
        _price.font = Kfont(18);
        _price.textColor = ThemeColor;
        _price.textAlignment = NSTextAlignmentLeft;
        [baseView addSubview:_price];
        
        UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(47.5),SCREEN_WIDTH - 2 * ScreenX375(13), ScreenX375(0.5))];
        line1.backgroundColor = REXADECIMALCOLOR(@"dcdcdc");
        [baseView addSubview:line1];
        
        UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(242.5),SCREEN_WIDTH - 2 * ScreenX375(13), ScreenX375(0.5))];
        line2.backgroundColor = REXADECIMALCOLOR(@"dcdcdc");
        [baseView addSubview:line2];
        
        NSArray *payimg = [[NSArray alloc] initWithObjects:@"微信支付",@"支付宝支付",@"银行卡支付",@"钱包余额支付", nil];
        
        NSString *height = [[NSString alloc] init];
        height = @"50";
        
        for (int i = 0; i < payimg.count; i++) {
            UIImageView *payimage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(63) + [height integerValue] * i, ScreenX375(22), ScreenX375(22))];
            payimage.image = [UIImage imageNamed:[payimg objectAtIndex:i]];
            [baseView addSubview: payimage];
            
            UILabel *payMethodText =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(45), ScreenX375(66) +[height integerValue] * i, ScreenX375(120), ScreenX375(14))];
            payMethodText.text = [payimg objectAtIndex:i];
            payMethodText.font = Kfont(14);
            payMethodText.textColor = REXADECIMALCOLOR(@"#333333");
            payMethodText.textAlignment = NSTextAlignmentLeft;
            [baseView addSubview:payMethodText];
        }
        
        for (int i = 0;i < 3; i++) {
            UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(96.5) + [height integerValue] * i, SCREEN_WIDTH - ScreenX375(26), 0.5)];
            line.image = [UIImage imageNamed:@"虚线"];
            [baseView addSubview:line];
        }
        
        UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(273), SCREEN_WIDTH - ScreenX375(26), ScreenX375(44))];
        payBtn.backgroundColor = ThemeColor;
        payBtn.layer.cornerRadius = ScreenX375(22);
        payBtn.clipsToBounds = YES;
        [payBtn setTitle:@"立即支付" forState:UIControlStateNormal];
        [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        payBtn.titleLabel.font = Kfont(16);
        [payBtn addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:payBtn];
        
        
        _weiXinPay = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(345), ScreenX375(63),ScreenX375(16), ScreenX375(16))];
        [_weiXinPay setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [_weiXinPay setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
        _weiXinPay.selected = YES;
        [_weiXinPay addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:_weiXinPay];
        
        _aLiPay = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(345), ScreenX375(113),ScreenX375(16), ScreenX375(16))];
        [_aLiPay setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [_aLiPay setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
        [_aLiPay addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:_aLiPay];
        
        _bankCardPay = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(345), ScreenX375(163),ScreenX375(16), ScreenX375(16))];
        [_bankCardPay setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [_bankCardPay setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
        [_bankCardPay addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:_bankCardPay];
        
        _balancePay = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(345), ScreenX375(213),ScreenX375(16), ScreenX375(16))];
        [_balancePay setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [_balancePay setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
        [_balancePay addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:_balancePay];
    }
    return self;
}

-(void)hidden{
    if (_hiddenClick) {
        _hiddenClick();
    }
}

-(void)done{
    if (_doneClick) {
        _doneClick();
    }
}

-(void)selectType:(UIButton *)button{
    if (_balancePay == button) {
        _balancePay.selected = YES;
        _aLiPay.selected = NO;
        _weiXinPay.selected = NO;
        _bankCardPay.selected = NO;
        _is_weiXin = NO;
        _is_aLiPay = NO;
        _is_bankCard = NO;
        _is_wallet = YES;
    }else if (_aLiPay == button){
        _balancePay.selected = NO;
        _aLiPay.selected = YES;
        _weiXinPay.selected = NO;
        _bankCardPay.selected = NO;
        _is_weiXin = NO;
        _is_aLiPay = YES;
        _is_bankCard = NO;
        _is_wallet = NO;
    }else if (_weiXinPay == button){
        _balancePay.selected = NO;
        _aLiPay.selected = NO;
        _weiXinPay.selected = YES;
        _bankCardPay.selected = NO;
        _is_weiXin = YES;
        _is_aLiPay = NO;
        _is_bankCard = NO;
        _is_wallet = NO;
    }else{
        _balancePay.selected = NO;
        _aLiPay.selected = NO;
        _weiXinPay.selected = NO;
        _bankCardPay.selected = YES;
        _is_weiXin = NO;
        _is_aLiPay = NO;
        _is_bankCard = YES;
        _is_wallet = NO;
    }
}


@end
